package com.odriver.neulearn.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.odriver.neulearn.Bean.MenuBean;
import com.odriver.neulearn.R;
import com.odriver.neulearn.Util.TransferUtil;

import java.util.List;

/**
 * Created by yeruyi on 2016/11/28.
 */

public class LearnListviewAdapter extends BaseAdapter {

    private List<CourseLearnBean.CourseListBean> data;
    private LayoutInflater inflate;
    private Context context;

    public LearnListviewAdapter(Context context, List<CourseLearnBean.CourseListBean> data) {
        this.data = data;
        this.context = context;
        inflate = LayoutInflater.from(context);
    }

    public void updateData(List<CourseLearnBean.CourseListBean> data) {
        if (this.data != null) {
            this.data.clear();
        }
        this.data = data;
        notifyDataSetChanged();

    }

    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data != null ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = inflate.inflate(R.layout.item_learn_listview, null);
            viewHolder.topic = (TextView) convertView.findViewById(R.id.idp_item_learn_topic);
            viewHolder.smallTopic = (TextView) convertView.findViewById(R.id.idp_item_learn_topic_small);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        CourseLearnBean.CourseListBean data = (CourseLearnBean.CourseListBean) this.getItem(position);
        viewHolder.topic.setText(data.getTitle());
        viewHolder.smallTopic.setText("" + data.getTime() + "分钟");
        return convertView;
    }

    static class ViewHolder {
        TextView topic, smallTopic;
    }
}
